from .basic import *
import logging

WSGI_APPLICATION = 'wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'pingtai',
        'USER': 'root',
        'PASSWORD': 'Root@W<2<jushq@-T',
        'HOST': '192.168.3.36',
        'PORT': '3306',
    }
}

# 其他配置
REDIS_HOST = "192.168.3.36"
REDIS_DB = 0
REDIS_PORT = "6379"

# celery 配置

BROKER_URL = 'amqp://guest:123123@rabbitmq:5672/long'  # 使用RabbitMQ作为消息代理
CELERY_RESULT_BACKEND = 'redis://192.168.3.36:6379/5'  # 把任务结果存在了Redis

# mqtt
BROKER = "192.168.3.36"
PORT = 21026
WAIT_TIME = 30
EMQ_LIST_URL = "http://192.168.3.36:21029/api/v4/clients/"
# 配置键
SCRIPTS_FILE_DIR = r"/pingtai_files/script_pag"
TAC_DEPLOY_FILE_DIR = "r/pingtai_files/tac_deploys"
TAC_DEPLOY_JSON_FILE_DIR = "r/pingtai_files/tac_deploys_json"
DEPLOY_FILE_DIR = r"/pingtai_files/deploys"
DEPLOY_JSON_FILE_DIR = r"/pingtai_files/deploys_json"
TEMP_FILE_DIR = r"/pingtai_files/temp"

# 升级包文件所在目录
UPDATE_GATEWAY_FILE_PATH = r"/pingtai_files/uploads/gateway"
UPDATE_SENSOR_FILE_PATH = r"/pingtai_files/uploads/sensor"
AGREEMENT_FILE_PATH = r"/pingtai_files/uploads/agreement"
CONFIG_FILE_PATH = r"/pingtai_files/uploads/config"
JSON_CONFIG_FILE_PATH = r"/pingtai_files/json_config"
TAC_JSON_CONFIG_FILE_PATH = r"/pingtai_files/tac_json_config"


# 日志文件所在目录
LOG_FILE_PATH = r"/pingtai_files/uploads/dailys"

# 拼接的http
DOWNURL = "http://192.168.3.36:21032/api/file/down/"
UPLOADURL = "http://192.168.3.36:21032/api/file/upload/"
REMOVEFILE = "http://192.168.3.36:21032/api/file/remove_file?{}"
GET_MD5 = "http://192.168.3.36:21032/api/file/get_md5?{}&{}"
ANA_FILE = "http://192.168.3.36:21032/api/file/ana_file?{}"
IS_FILE = "http://192.168.3.36:21032/api/file/is_file?{}"
HISTORY_FRESH = "http://192.168.3.36:21032/api/history/fresh?{}"
AWAKE_GATEWAY = "http://192.168.3.36:21032/api/new_gateway/awake?{}"

# 下载配置文件
DOWN_DEPLOY = 10

# 网关clientid配置
ID_HEAD = "TIAID"
ID_END = "-2"

LOGGING_DIR = "/logs"
if not os.path.exists(LOGGING_DIR):
    os.mkdir(LOGGING_DIR)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'standard': {
            'format': '[%(levelname)s][%(asctime)s][%(filename)s][%(funcName)s][%(lineno)d] > %(message)s'
        },
        'simple': {
            'format': '[%(levelname)s]> %(message)s'
        },
    },
    'filters': {
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'filters': ['require_debug_true'],
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
        },
        'file_handler': {
            'level': 'INFO',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'filename': '%s/django.log' % LOGGING_DIR,
            'formatter': 'standard'
        },  # 用于文件输出
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
            'formatter': 'standard'
        },
    },
    'loggers': {
        'mdjango': {
            'handlers': ['console', 'file_handler'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
    }
}

LOGGER = logging.getLogger("mdjango")
